package app.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import app.sys.model.RetCode;
import app.sys.data.entity.Menu;
import app.sys.mapper.MenuMapper;
import app.sys.model.ResponseObj;
import app.sys.service.MenuService;
import io.github.yedaxia.apidocs.ApiDoc;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * 菜单controller
 */
@ApiDoc
@RestController
@RequestMapping("/sys/menu")
public class MenuController extends BaseRestController<MenuService, MenuMapper, Menu,Long>{
    @Override
    protected QueryWrapper queryWrapper(QueryWrapper<Menu> wrapper) {
        wrapper.orderByDesc("create_time");
        return super.queryWrapper(wrapper);
    }

    /**
     * 菜单数据
     * @return
     */
    @PostMapping("/getMenusByUser")
    public ResponseObj<List> getMenusByUser(){
        //UserInfo loginUser = UserUtils.getLoginUser();
        List<Menu> menus = this.mapper.getMenusByUser(1L);
        return new ResponseObj<>(menus, RetCode.SUCCESS);
    }

    /**
     * 返回列表
     *
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @Override
    public ResponseObj<List<Menu>> list(Menu model) throws Exception {
        return super.list(model);
    }

    /**
     * 分页查询
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    @Override
    public ResponseObj<Page<Menu>> listPage(Page<Menu> page, Menu model) throws Exception {
        return super.listPage(page, model);
    }
    /**
     * 查询详情
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @Override
    public ResponseObj<Menu> detail(Long id) throws Exception {
        return super.detail(id);
    }
    /**
     * 新增
     *
     * @param object
     * @return
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @Override
    public ResponseObj<Boolean> insert(Menu object) throws Exception {
        return super.insert(object);
    }

    /**
     * 修改
     * @param object
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @Override
    public ResponseObj<Boolean> update(Menu object) throws Exception {
        return super.update(object);
    }

}
